Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jae/rangeprooffix #75

Merged
merged 7 commits into from
Jul 3, 2018
Merged

Jae/rangeprooffix #75

merged 7 commits into from
Jul 3, 2018

Conversation

jaekwon
Copy link
Contributor

@jaekwon jaekwon commented Jul 2, 2018

0.9.0 (July 1, 2018)

BREAKING CHANGES

  • RangeProof.VerifyItem doesn't require an index.
  • Only return values in range when getting proof.
  • Return keys as well.

BUG FIXES

  • traversal bugs in traverseRange.

Merging to develop early since the previous version is just broken.

Copy link
Contributor

@liamsi liamsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments about documentation and exported methods.
LGTM in general. develop needs to be merged in or rebased upon.

proof_range.go Outdated
// `i` is the relative index within this RangeProof.
// Also see LeftIndex().
// Verify that a key has some value.
// Does not assume that the proof itself is valid, call Verify() first.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is always intended to be used in combination with Verify(), then it would safer if we do not expose this functionality. In other words: Is there a use-case where we need to call VerifyItem(...) without Verify()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to call Verify without VerifyItem. If we're going to have a Verify() method, might as well have a separate VerifyItem method. We return an error if Verify() wasn't called first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true here but it is true here now: #78
In multi-layered merkle proofs, say, it is more efficient to not have the intermediate root hashes in the layered merkle proofs, so in that case you'll want to verify the leaves, but compute the root hash and override the root hash verification requirement by calling:

proof.Verify(proof.ComputeRootHash())

which is cheap due to memoization (in the linked PR) and enables the other verification functionality.

proof_range.go Outdated
@@ -236,24 +264,35 @@ func (proof *RangeProof) _verify(root []byte) (treeEnd bool, err error) {
// If keyStart or keyEnd don't exist, the leaf before keyStart
// or after keyEnd will also be included, but not be included in values.
// If keyEnd-1 exists, no later leaves will be included.
// If keyStart <= keyEnd and both not nil, panics.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be keyStart >= keyEnd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah oops.

proof_range.go Outdated
@@ -20,8 +21,21 @@ type RangeProof struct {
treeEnd int // 0 if not set, 1 if true, -1 if false.
}

func (proof *RangeProof) Keys() (keys [][]byte) {
Copy link
Contributor

@liamsi liamsi Jul 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used in the test below so far. Do you assume this will be useful for other purposes, too? As far as I can see, the keys are always returned (now) together with the range-proof (not sure why we need an additional public Keys() method).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yeah, the keys returned are the queried keys. the .Keys() in a RangeProof are all the keys for values queried + any other keys like the item before startKey if startKey is provided (not nil) and doesn't exist in the iavl store, so they're different in functionality. I'll add a comment saying so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Keys returns all the keys in the RangeProof.  NOTE: The keys here may
// include more keys than provided by tree.GetRangeWithProof or
// VersionedTree.GetVersionedRangeWithProof.  The keys returned there are only
// in the provided [startKey,endKey){limit} range.  The keys returned here may
// include extra keys, such as:
// - the key before startKey if startKey is provided and doesn't exist;
// - the key after a queried key with tree.GetWithProof, when the key is absent.
func (proof *RangeProof) Keys() (keys [][]byte) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. That makes sense.

proof_range.go Outdated
return proof.LeftPath.Index()
}

// `i` is the relative index within this RangeProof.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to explain what i is here? It is not a parameter/argument nor do we return it. It looks like an implementation detail. Looks like this comment belongs inside of the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in the new PR.

{start: 0xf8, end: 0x00, pnc: true}, // #19
{start: 0x10, end: 0x10, pnc: true}, // #20
{start: 0x12, end: 0x12, pnc: true}, // #21
{start: 0xff, end: 0xf7, pnc: true}, // #22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exemplary testing 👍

@jaekwon
Copy link
Contributor Author

jaekwon commented Jul 2, 2018

I pushed fixes to #78

@liamsi
Copy link
Contributor

liamsi commented Jul 2, 2018

Reviewed #78. LGTM

@liamsi
Copy link
Contributor

liamsi commented Jul 3, 2018

Merged #78 and resolved conflicts to develop. Will merge if ci goes through.

@liamsi liamsi merged commit 0b6f4eb into develop Jul 3, 2018
liamsi added a commit that referenced this pull request Jul 3, 2018
* VerifyItem takes no index; Return keys/values in range; Fix

* compute hash from rangeproof

* Require Verify() before Verify*()

* Review fixes from #75

* Bump version, update changelog
mossid pushed a commit to mossid/iavl that referenced this pull request Aug 30, 2018
0.9.1 -- compute hash from rangeproof

Require Verify() before Verify*()

Review fixes from cosmos#75

First commit for generalized merkle proofs

Fix imports

Bump version to 0.9.3

Return nil on empty tree - bump version to 0.10.0

Add OpDecoders

fix test

finalize rebase
mossid pushed a commit to mossid/iavl that referenced this pull request Aug 30, 2018
0.9.1 -- compute hash from rangeproof

Require Verify() before Verify*()

Review fixes from cosmos#75

First commit for generalized merkle proofs

Fix imports

Bump version to 0.9.3

Return nil on empty tree - bump version to 0.10.0

Add OpDecoders

fix test

finalize rebase

fix test
mossid pushed a commit to mossid/iavl that referenced this pull request Aug 30, 2018
0.9.1 -- compute hash from rangeproof

Require Verify() before Verify*()

Review fixes from cosmos#75

First commit for generalized merkle proofs

Fix imports

Bump version to 0.9.3

Return nil on empty tree - bump version to 0.10.0

Add OpDecoders

fix test

finalize rebase

fix test

fix toml
danil-lashin pushed a commit to danil-lashin/iavl that referenced this pull request Oct 24, 2018
* 'develop' of github.com:danil-lashin/iavl:
  Prep Release 0.11.0 (cosmos#111)
  Remove architecture dependent getter functions (cosmos#96)
  Use 8 bytes to store int64 components of database keys  (cosmos#107)
  Update to CircleCI 2.0 (cosmos#108)
  Release 0.10.0: Update Changelog and bump version (cosmos#99)
  delete empty file (relict from merging master into develop)
  Mutable/Immutable refactor and GetImmutable snapshots (cosmos#92)
  Remove unreachable code
  Remove unused variable
  dep: Change tendermint dep to be ^v0.22.0 (cosmos#91)
  Fix benchmark scripts for current code (cosmos#89)
  release v0.9.2 (cosmos#82)
  Various lints (cosmos#80)
  Jae/rangeprooffix (cosmos#75)
ridenaio pushed a commit to idena-network/iavl that referenced this pull request Jul 1, 2019
* VerifyItem takes no index; Return keys/values in range; Fix

* Bump version

* 0.9.1 -- compute hash from rangeproof

* Require Verify() before Verify*()

* Review fixes from cosmos#75
ridenaio pushed a commit to idena-network/iavl that referenced this pull request Jul 1, 2019
* VerifyItem takes no index; Return keys/values in range; Fix

* compute hash from rangeproof

* Require Verify() before Verify*()

* Review fixes from cosmos#75

* Bump version, update changelog
ridenaio pushed a commit to idena-network/iavl that referenced this pull request Jul 1, 2019
0.9.1 -- compute hash from rangeproof

Require Verify() before Verify*()

Review fixes from cosmos#75

First commit for generalized merkle proofs

Fix imports

Bump version to 0.9.3

Return nil on empty tree - bump version to 0.10.0

Add OpDecoders

fix test

finalize rebase

fix test

fix toml
@tac0turtle tac0turtle deleted the jae/rangeprooffix branch July 11, 2019 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants